<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <!-- 移动端设置不缩放 -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>博客发布</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
        <link rel="stylesheet" th:href="@{/plugin/editor-md/css/editormd.min.css}">
        <link rel="stylesheet" th:href="@{/css/common.css}">
        <link rel="stylesheet" th:href="@{/css/admin/blog-publish.css}">
    </head>
    <body>
        <!-- navbar -->
        <nav th:replace="_fragment::admin-navbar(0)"></nav>
        
        <!-- content -->
        <div>
            <div class="container">
                <h3>博客发布</h3>
                <div class="row m-container">
                    <div class="col-sm-10 col-sm-offset-1">
                        <form id="article-form">
                            <!-- title -->
                            <div class="input-group">
                                <div class="input-group-btn">
                                    <input type="hidden" id="flag" value="0">
                                    <select class="form-control" name="fileType" id="fileType" title="fileType">
                                        <option value="0" th:selected="${blog != null ? (blog.flag == 0 ? 'selected' : null) : null}">原创</option>
                                        <option value="1" th:selected="${blog != null ? (blog.flag == 1 ? 'selected' : null) : null}">转载</option>
                                    </select>
                                </div>
                                <input class="form-control" id="title" type="text" placeholder="标题" th:value="${blog != null ? blog.title : ''}" required>
                            </div>
                            <!-- cover -->
                            <div class="input-group interval">
                                <span class="input-group-addon" id="image-addon">Cover</span>
                                <input id="cover" th:value="${blog != null ? blog.cover : ''}" type="text" class="form-control" name="image-url" aria-describedby="image-addon" placeholder="http(s):// ..." required>
                            </div>
                            <!-- types & tags -->
                            <div class="row interval">
                                <!-- types -->
                                <div class="col-sm-6">
                                    <div class="input-group">
                                        <input type="hidden" id="typeId" th:value="${blog != null ? blog.type.id : ''}">
                                        <span class="input-group-addon" id="article-type-addon">分类</span>
                                        <select class="form-control" name="types" id="types" required>
                                            <option value="">分类</option>
                                            <option th:each="type: ${types}" th:value="${type.id}" th:text="${type.name}" th:selected="${blog != null ? (blog.type.id == type.id ? 'selected' : null) : null}"></option>
                                        </select>
                                    </div>
                                </div>
                                <!-- tags -->
                                <div class="col-sm-6">
                                    <div class="input-group">
                                        <span class="input-group-addon" id="article-tag-addon">标签</span>
                                        <select class="selectpicker form-control" id="tags" multiple data-live-search="true" data-live-search-placeholder="搜索">
                                            <option th:each="tag: ${tags}" th:value="${tag.id}" th:text="${tag.name}" th:selected="${blog != null ? (#sets.contains(blog.tags, tag) ? 'selected' : null) : null}"></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <!-- summary -->
                            <div class="interval">
                                <textarea id="summary" th:text="${blog != null ? blog.summary : ''}" class="form-control" rows="3" placeholder="摘要..." required></textarea>
                            </div>
                            <!-- content -->
                            <div class="interval">
                                <div id="eritor-md-content">
                                    <textarea id="content" th:text="${blog != null ? blog.content : ''}" class="form-control" placeholder="正文..." style="display: none;" required>
#### Disabled options

- TeX (Based on KaTeX);
- Emoji;
- Task lists;
- HTML tags decode;
- Flowchart and Sequence Diagram;</textarea>
                                </div>
                            </div>
                            <!-- other options -->
                            <div class="interval">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="recommend" name="recommend" th:checked="${blog != null ? (blog.recommend ? 'checked' : null) : 'checked'}">
                                    <label class="form-check-label" for="recommend">推荐</label>
                                    <input class="form-check-input" type="checkbox" id="reward" name="reward" th:checked="${blog != null ? (blog.appreciation ? 'checked' : null) : 'checked'}">
                                    <label class="form-check-label" for="reward">赞赏</label>
                                    <input class="form-check-input" type="checkbox" id="transfer" name="transfer" th:checked="${blog != null ? (blog.shareStatement ? 'checked' : null) : 'checked'}">
                                    <label class="form-check-label" for="transfer">转载声明</label>
                                    <input class="form-check-input" type="checkbox" id="comment" name="comment" th:checked="${blog != null ? (blog.commentable ? 'checked' : null) : 'checked'}">
                                    <label class="form-check-label" for="comment">评论</label>
                                </div>
                                <input id="id" type="hidden" th:value="${blog != null ? blog.id : ''}">
<!--                                <input id="views" type="hidden" th:value="${blog != null ? blog.views : 0}">-->
<!--                                <input id="createTime" type="hidden" th:value="${blog != null ? #dates.format(blog.createTime, 'yyyy-MM-dd HH:mm:ss') : ''}">-->
                            </div>
                            <!-- button -->
                            <div class="interval pull-right">
                                <div class="btn btn-default" onclick="window.history.go(-1)">返回</div>
                                <div class="btn btn-default" th:onclick="'submitBlog(' + ${blog == null ? null : blog.id} + ', false)'">保存</div>
                                <div class="btn btn-success" th:onclick="'submitBlog(' + ${blog == null ? null : blog.id} + ', true)'">发布</div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>  
        </div>

        <!-- footer -->
        <footer th:replace="_fragment::footer"></footer>

        <script src="https://cdn.staticfile.org/jquery/3.2.0/jquery.min.js"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" ></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
        <!-- bootstrap-select 本地化 -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/i18n/defaults-zh_CN.min.js"></script>
        <script th:src="@{/plugin/editor-md/editormd.min.js}"></script>
        <script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
        <script th:src="@{/js/common.js}"></script>
        <script th:src="@{/js/admin/blog-publish.js}"></script>
    </body>
</html>